package com.cfuture08.home.action.user;

import com.cfuture08.eweb4j.component.dwz.vo.Menu;
import com.cfuture08.eweb4j.helper.ORMConfigBeanWriter;
import com.cfuture08.eweb4j.mvc.action.Action;
import com.cfuture08.eweb4j.mvc.action.ActionSupport;
import com.cfuture08.eweb4j.orm.dao.DAO;
import com.cfuture08.home.vo.AdminReply;
import com.cfuture08.home.vo.ArtAttach;
import com.cfuture08.home.vo.ArtCate;
import com.cfuture08.home.vo.ArtComment;
import com.cfuture08.home.vo.Article;
import com.cfuture08.home.vo.Message;
import com.cfuture08.home.vo.Perm;
import com.cfuture08.home.vo.Role;
import com.cfuture08.home.vo.RolePerm;
import com.cfuture08.home.vo.User;
import com.cfuture08.home.vo.Work;

public class Login extends ActionSupport {
	private User user;

	public String execute() {
		String result = null;
		this.user = DAO.selectOne(this.user, new String[] { "account",
				"password" });
		if (this.user != null) {
			this.request.getSession().setAttribute("loginUser", this.user);
			result = Action.SUCCESS;
		} else {
			this.request.setAttribute("loginError", "账号或密码错误。");
			result = Action.INPUT;
		}

		return result;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public static void testLogin() {
		Login login = new Login();
		User user = new User();
		user.setAccount("test");
		user.setPassword("1234s56");
		login.setUser(user);
		System.out.println(login.execute());
	}

	public static void main(String[] args) {
		ORMConfigBeanWriter.write("eweb4j-orm-config.xml", User.class,
				AdminReply.class, ArtAttach.class, ArtCate.class,
				ArtComment.class, Article.class, Message.class, Perm.class,
				Role.class, RolePerm.class, User.class, Work.class, Menu.class);
		/*
		 * String error = EWeb4JConfig.start(); if (error == null) {
		 * Login.testLogin(); } else { System.out.println(error); }
		 */
	}
}
